home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / phozon.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  7KB  |  246 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11. #include "cpu/m6809/m6809.h"
  12.  
  13. unsigned char *phozon_snd_sharedram;
  14. unsigned char *phozon_spriteram;
  15. unsigned char *phozon_customio_1, *phozon_customio_2;
  16. static int credits, coincounter1, coincounter2;
  17.  
  18. void phozon_init_machine( void )
  19. {
  20.     credits = coincounter1 = coincounter2 = 0;
  21.     cpu_set_halt_line(1, CLEAR_LINE);
  22.     cpu_set_halt_line(2, CLEAR_LINE);
  23. }
  24.  
  25. /* memory handlers */
  26. READ_HANDLER( phozon_spriteram_r ){
  27.     return phozon_spriteram[offset];
  28. }
  29.  
  30. WRITE_HANDLER( phozon_spriteram_w ){
  31.    phozon_spriteram[offset] = data;
  32. }
  33.  
  34. READ_HANDLER( phozon_snd_sharedram_r ){
  35.     return phozon_snd_sharedram[offset];
  36. }
  37.  
  38. WRITE_HANDLER( phozon_snd_sharedram_w ){
  39.     phozon_snd_sharedram[offset] = data;
  40. }
  41.  
  42. /* cpu control functions */
  43. WRITE_HANDLER( phozon_cpu2_enable_w ){
  44.     cpu_set_halt_line(1, offset ? CLEAR_LINE : ASSERT_LINE);
  45. }
  46.  
  47. WRITE_HANDLER( phozon_cpu3_enable_w ){
  48.     cpu_set_halt_line(2, offset ? CLEAR_LINE : ASSERT_LINE);
  49. }
  50.  
  51. WRITE_HANDLER( phozon_cpu3_reset_w ){
  52.     cpu_set_reset_line(2,PULSE_LINE);
  53. }
  54.  
  55. /************************************************************************************
  56. *                                                                                    *
  57. *           Phozon custom I/O chips (preliminary)                                        *
  58. *                                                                                    *
  59. ************************************************************************************/
  60.  
  61. WRITE_HANDLER( phozon_customio_1_w )
  62. {
  63.     phozon_customio_1[offset] = data;
  64. }
  65.  
  66. WRITE_HANDLER( phozon_customio_2_w )
  67. {
  68.     phozon_customio_2[offset] = data;
  69. }
  70.  
  71. static int credmoned [] = { 1, 1, 1, 1, 1, 2, 2, 3 };
  72. static int monedcred [] = { 1, 2, 3, 6, 7, 1, 3, 1 };
  73.  
  74. READ_HANDLER( phozon_customio_1_r )
  75. {
  76.     int mode, val, temp1, temp2;
  77.  
  78.     mode = phozon_customio_1[8];
  79.     if (mode == 3)    /* normal mode */
  80.     {
  81.         switch (offset)
  82.         {
  83.             case 0:     /* Coin slots */
  84.             {
  85.                 static int lastval;
  86.  
  87.                 val = (readinputport( 2 ) >> 4) & 0x03;
  88.                 temp1 = readinputport( 0 ) & 0x07;
  89.                 temp2 = (readinputport( 0 ) >> 5) & 0x07;
  90.  
  91.                 /* bit 0 is a trigger for the coin slot 1 */
  92.                 if ((val & 1) && ((val ^ lastval) & 1))
  93.                 {
  94.                     coincounter1++;
  95.                     if (coincounter1 >= credmoned[temp1])
  96.                     {
  97.                         credits += monedcred [temp1];
  98.                         coincounter1 -= credmoned [temp1];
  99.                     }
  100.                 }
  101.                 /* bit 1 is a trigger for the coin slot 2 */
  102.                 if ((val & 2) && ((val ^ lastval) & 2))
  103.                 {
  104.                     coincounter2++;
  105.                     if (coincounter2 >= credmoned[temp2])
  106.                     {
  107.                         credits += monedcred [temp2];
  108.                         coincounter2 -= credmoned [temp2];
  109.                     }
  110.                 }
  111.  
  112.                 if (credits > 99)
  113.                     credits = 99;
  114.  
  115.                 return lastval = val;
  116.             }
  117.                 break;
  118.             case 1:
  119.             {
  120.                 static int lastval;
  121.  
  122.                 val = readinputport( 2 ) & 0x03;
  123.                 temp1 = readinputport( 0 ) & 0x07;
  124.                 temp2 = (readinputport( 0 ) >> 5) & 0x07;
  125.  
  126.                 /* bit 0 is a trigger for the 1 player start */
  127.                 if ((val & 1) && ((val ^ lastval) & 1))
  128.                 {
  129.                     if (credits > 0)
  130.                         credits--;
  131.                     else
  132.                         val &= ~1;   /* otherwise you can start with no credits! */
  133.                 }
  134.                 /* bit 1 is a trigger for the 2 player start */
  135.                 if ((val & 2) && ((val ^ lastval) & 2))
  136.                 {
  137.                     if (credits >= 2)
  138.                         credits -= 2;
  139.                     else
  140.                         val &= ~2;   /* otherwise you can start with no credits! */
  141.                 }
  142.                 return lastval = val;
  143.             }
  144.                 break;
  145.             case 2:
  146.                 return (credits / 10);      /* high BCD of credits */
  147.                 break;
  148.             case 3:
  149.                 return (credits % 10);      /* low BCD of credits */
  150.                 break;
  151.             case 4:
  152.                 return (readinputport( 3 ) & 0x0f);   /* 1P controls */
  153.                 break;
  154.             case 5:
  155.                 return (readinputport( 4 ) & 0x03);   /* 1P button 1 */
  156.                 break;
  157.             default:
  158.                 return 0x0;
  159.         }
  160.     }
  161.     else if (mode == 5)    /* IO tests */
  162.     {
  163.         switch (offset)
  164.         {
  165.             case 0x00: val = 0x00; break;
  166.             case 0x01: val = 0x02; break;
  167.             case 0x02: val = 0x03; break;
  168.             case 0x03: val = 0x04; break;
  169.             case 0x04: val = 0x05; break;
  170.             case 0x05: val = 0x06; break;
  171.             case 0x06: val = 0x0c; break;
  172.             case 0x07: val = 0x0a; break;
  173.             default:
  174.                 val = phozon_customio_1[offset];
  175.         }
  176.     }
  177.     else if (mode == 1)    /* test mode controls */
  178.     {
  179.         switch (offset)
  180.         {
  181.             case 4:
  182.                 return (readinputport( 2 ) & 0x03);    /* start 1 & 2 */
  183.                 break;
  184.             case 5:
  185.                 return (readinputport( 3 ) &0x0f);    /* 1P controls */
  186.                 break;
  187.             case 7:
  188.                 return (readinputport( 4 ) & 0x03);    /* 1P button 1 */
  189.                 break;
  190.             default:
  191.                 return phozon_customio_1[offset];
  192.         }
  193.     }
  194.     else
  195.         val = phozon_customio_1[offset];
  196.     return val;
  197. }
  198.  
  199. READ_HANDLER( phozon_customio_2_r )
  200. {
  201.     int mode, val;
  202.  
  203.     mode = phozon_customio_2[8];
  204.     if (mode == 8)    /* IO tests */
  205.     {
  206.         switch (offset)
  207.         {
  208.             case 0x00: val = 0x01; break;
  209.             case 0x01: val = 0x0c; break;
  210.             default:
  211.                 val = phozon_customio_2[offset];
  212.         }
  213.     }
  214.     else if (mode == 9)
  215.     {
  216.         switch (offset)    /* TODO: coinage B & check bonus life bits */
  217.         {
  218.             case 0:
  219.                 val = (readinputport( 0 ) & 0x08) >> 3;        /* lives (bit 0) */
  220.                 val |= (readinputport( 0 ) & 0x01) << 2;    /* coinage A (bit 0) */
  221.                 val |= (readinputport( 0 ) & 0x04) << 1;    /* coinage A (bit 2) */
  222.                 break;
  223.             case 1:
  224.                 val = (readinputport( 0 ) & 0x10) >> 4;        /* lives (bit 1) */
  225.                 val |= (readinputport( 1 ) & 0xc0) >> 5;    /* bonus life (bits 1 & 0) */
  226.                 val |= (readinputport( 0 ) & 0x02) << 2;    /* coinage A (bit 1) */
  227.                 break;
  228.             case 2:
  229.                 val = (readinputport( 1 ) & 0x07) << 1;        /* rank */
  230.                 break;
  231.             case 4:    /* some bits of coinage B (not implemented yet) */
  232.                 val = 0;
  233.                 break;
  234.             case 6:
  235.                 val = readinputport( 1 ) & 0x08;            /* test mode */
  236.                 val |= (readinputport( 2 ) & 0x80) >> 5;    /* cabinet */
  237.                 break;
  238.             default:
  239.                 val = phozon_customio_2[offset];
  240.         }
  241.     }
  242.     else
  243.         val = phozon_customio_2[offset];
  244.     return val;
  245. }
  246.